package com.haizhi.crm.biz.task.message.queue;

import com.haizhi.crm.biz.task.message.model.ContextDto;
import com.haizhi.crm.common.log.GLog;
import com.haizhi.crm.common.log.LogFactory;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * Created by wangshan on 2018/5/29.
 */
public class Container {
    private static final GLog LOG = LogFactory.getLogger(Container.class);
    private static final int QUEUE_SIZE = 10000;
    private static ArrayBlockingQueue<ContextDto> messages = new ArrayBlockingQueue<ContextDto>(QUEUE_SIZE);

    public static void put(ContextDto contextDto) {
        try {
            messages.put(contextDto);
        } catch (InterruptedException e) {
            LOG.error("produce message error for message put been interrupted" );
        }
    }

    public static ContextDto take() {
        try {
            return messages.take();
        } catch (InterruptedException e) {
            LOG.error("take message error for get message been interrupted" );
        }
        return null;
    }

}
